package ua.pp.bizon.cripto.file;

import java.io.File;

public abstract class Path implements IPath {
    
    /* (non-Javadoc)
     * @see ua.pp.bizon.cripto.file.IPathFile#toString()
     */
    @Override
    public String toString() {
        return "Path [place=" + place + ", path=" + path + ", username=" + username + ", host=" + host + "]";
    }

    private Place place;
    private String path;
    private String username;
    private String password;
    private String host;
    
    public Path(Place place, String url) {
        super();
        this.place = place;
        this.path = url;
        if (path.startsWith("~" + File.separator)) {
            path = System.getProperty("user.home") + path.substring(1);
        }
    }
    
    public Path(Place place, String path, String username, String password, String host) {
        super();
        this.place = place;
        this.path = path;
        this.username = username;
        this.password = password;
        this.host = host;
    }

    /* (non-Javadoc)
     * @see ua.pp.bizon.cripto.file.IPathFile#getPlace()
     */
    @Override
    public Place getPlace() {
        return place;
    }
    /* (non-Javadoc)
     * @see ua.pp.bizon.cripto.file.IPathFile#getPath()
     */
    @Override
    public String getPath() {
        return path;
    }
    /* (non-Javadoc)
     * @see ua.pp.bizon.cripto.file.IPathFile#getUsername()
     */
    @Override
    public String getUsername() {
        return username;
    }
    /* (non-Javadoc)
     * @see ua.pp.bizon.cripto.file.IPathFile#getPassword()
     */
    @Override
    public String getPassword() {
        return password;
    }

    /* (non-Javadoc)
     * @see ua.pp.bizon.cripto.file.IPathFile#getHost()
     */
    @Override
    public String getHost() {
        return host;
    }

    /* (non-Javadoc)
     * @see ua.pp.bizon.cripto.file.IPathFile#getLastPathName()
     */
    @Override
    public String getLastPathName() {
        String normalizedTo = path.replaceAll("\\\\", "/");
        String[] pathes = normalizedTo.split("/");
         
        return pathes[pathes.length -1].isEmpty() ? pathes[pathes.length -2] : pathes[pathes.length -1];
    }
    
    
}
